#!/bin/bash
DEST_FILE=./src/rc.local/device_i2ceeprom.h
tmpstr=$(grep "/sys/bus/i2c/devices/*" src/rc.local/port_conf.h  | awk '{printf $3}')
I2C_EEPROM_PATH=${tmpstr%%,*}
if [ -n "$I2C_EEPROM_PATH" ]; then
	echo "find I2C_EEPROM_PATH: ${I2C_EEPROM_PATH} [OK]"
	I2C_SYSROM_ROOT="${I2C_EEPROM_PATH#*\"}"
	I2C_SYSROM_ROOT="${I2C_SYSROM_ROOT%\/*}"
	DEST_FILE=./src/rc.local/device_i2ceeprom.h
	echo "#ifndef __DEVICE_I2CEEPROM_H" > ${DEST_FILE}
	echo "#define __DEVICE_I2CEEPROM_H" >> ${DEST_FILE}

	echo -e "#define I2C_EEPROM_PATH \t${I2C_EEPROM_PATH}" >> ${DEST_FILE}
	echo -e "#define I2C_SYSROM_PATH \t\"${I2C_SYSROM_ROOT}/.sysrom\"" >> ${DEST_FILE}

	echo "#endif"  >> ${DEST_FILE}
	echo "generate ${DEST_FILE} [OK]"
	echo "${DEST_FILE}:"
	cat ${DEST_FILE}
else
	echo "find I2C_EEPROM_PATH [FAILED]"
	echo "#ifndef __DEVICE_I2CEEPROM_H" > ${DEST_FILE}
	echo "#define __DEVICE_I2CEEPROM_H" >> ${DEST_FILE}
	echo "#endif"  >> ${DEST_FILE}
	echo "generate ${DEST_FILE} [OK]"
	echo "${DEST_FILE}:"
	cat ${DEST_FILE}
fi
